//
//  TieDeatailViewController.m
//  Car
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "TieDeatailViewController.h"
#import "TieDeatailHeaderView.h"
#import "TieDeatailCell0.h"
#import "TieDetailCell1.h"
#import "UMSocial.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface TieDeatailViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UMSocialUIDelegate>

@property (nonatomic, strong) TieDeatailHeaderView *bar;
@property (nonatomic, strong) UICollectionView *collection;

@end

@implementation TieDeatailViewController



- (void)viewWillAppear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)creatBar {
    self.bar = [[TieDeatailHeaderView alloc] initWithFrame:CGRectMake(0, 15*HEIGHT/667, WIDTH, 55*HEIGHT/667) Completion:^(UITouch *touch) {
        [self.navigationController popViewControllerAnimated:YES];
    } WithMore:^(UITouch *touch) {
         [UMSocialSnsService presentSnsIconSheetView:self appKey:@"561cb0a267e58ed7c2004b02" shareText:[NSString stringWithFormat:@"http://a.xcar.com.cn/interface/6.0/bbs_detail.php?tid=%@&themeType=white&network=wifi&deviceType=iOS&type=0&version=6.2.3&fontSize=normal&p=1", _discuss.postId] shareImage:nil shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil] delegate:self];
    }];
    [self.bar.seg addTarget:self action:@selector(tab:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.bar];
    
}

- (void)tab:(UISegmentedControl *)seg {
    if (seg.selectedSegmentIndex == 0) {
        [self.collection setContentOffset:CGPointMake(0, 0) animated:NO];
    } else if (seg.selectedSegmentIndex == 1) {
        [self.collection setContentOffset:CGPointMake(WIDTH, 0) animated:NO];
    }
}


- (void)creatCollectin {
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    flow.itemSize = CGSizeMake(self.view.frame.size.width, HEIGHT - 15*HEIGHT/667);
    flow.minimumLineSpacing = 0;
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 65*HEIGHT/667, WIDTH, HEIGHT) collectionViewLayout:flow];
    [self.view addSubview:self.collection];
    self.collection.backgroundColor = [UIColor redColor];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    [self.collection registerClass:[TieDeatailCell0 class] forCellWithReuseIdentifier:@"select"];
    [self.collection registerClass:[TieDetailCell1 class] forCellWithReuseIdentifier:@"hot"];
    self.collection.backgroundColor = [UIColor whiteColor];
    self.collection.scrollEnabled = NO;
    self.collection.showsHorizontalScrollIndicator = NO;
}

- (void)setDiscuss:(YZLDiscuss *)discuss {
    if (_discuss != discuss) {
        _discuss = discuss;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatBar];
    [self creatCollectin];
    
    //返回
    [self skipReturnWithTarget:self];
    
    //bar颜色
    [self navigationbarColor];

    // Do any additional setup after loading the view.
}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.item) {
        TieDeatailCell0 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"select" forIndexPath:indexPath];
        cell.discuss = self.discuss;
        return cell;
    } else {
        TieDetailCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hot" forIndexPath:indexPath];
        cell.discuss = self.discuss;
        return cell;
    }
}

+ (instancetype)shareTieDeatailViewController {
    static TieDeatailViewController *detail = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        detail = [[TieDeatailViewController alloc] init];
        
    });
    return detail;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
